package com.example.pushMessage;

import com.example.entity.Payload;
import com.example.entity.Request;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;

import java.io.IOException;

/**
 * united message handler between pull and push
 */
public interface RocketmqMessageHandler<T extends Payload, L extends RocketmqPushMessageListener> {
    default String topic(Class<L> clazz) {
        RocketMQMessageListener annotation = clazz.getAnnotation(RocketMQMessageListener.class);
        if (annotation == null) {
            throw new RuntimeException("special L is invalid");
        }
        return annotation.topic();
    }

    String selectorExpression();

    void consuming(Request<T> request) throws IOException;
}